﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Benefit.Models.ServerData
{
    /// <summary>
    /// 成交明细
    /// </summary>
    public class T_TradeDetail_Summary
    {
        /// <summary>
        /// 编号
        /// </summary>
        public int Id { get; set; }
        /// <summary>
        /// 帐户
        /// </summary>
        public int AccountId { get; set; }
        /// <summary>
        /// 合约
        /// </summary>
        public string InstrumentId { get; set; }
        /// <summary>
        /// 经纪公司代码
        /// </summary>
        public string Brokerid { get; set; }
        /// <summary>
        /// 投资者代码
        /// </summary>
        public string Investorid { get; set; }
        /// <summary>
        /// 多空方向
        /// </summary>
        public string Direction { get; set; }
        /// <summary>
        /// 投保
        /// </summary>
        public string HedgeFlag { get; set; }
        /// <summary>
        /// 开平标志
        /// </summary>
        public string OffsetFlag { get; set; }
        /// <summary>
        /// 成交价
        /// </summary>
        public double TradePrice { get; set; }
        /// <summary>
        /// 手数
        /// </summary>
        public int Volume { get; set; }
        /// <summary>
        /// 成交额
        /// </summary>
        public double TotalCost { get; set; }
        /// <summary>
        /// 手续费
        /// </summary>
        public double Commission { get; set; }
        /// <summary>
        /// 逐日平仓盈亏
        /// </summary>
        public double CloseProfit { get; set; }
        /// <summary>
        /// 逐笔平仓盈亏
        /// </summary>
        public double CloseProfit2 { get; set; }
        /// <summary>
        /// 交易日
        /// </summary>
        public string TradingDay { get; set; }
        /// <summary>
        /// 结算编号
        /// </summary>
        public int SettlementId { get; set; }



        ///// <summary>
        ///// 查询结算后的持仓明细情况
        ///// </summary>
        ///// <param name="accountid"></param>
        ///// <param name="pdate"></param>
        ///// <returns></returns>
        //private System.Collections.Generic.List<T_TradeDetail_Summary> GetInfo(string pdate)
        //{
        //    List<T_TradeDetail_Summary> tth = new List<T_TradeDetail_Summary>();
        //    T_Settle_History tsh = new T_Settle_History();
        //    int settlementid = tsh.GetDayMaxSettlementInfoId(pdate);
        //    if (settlementid != -1)
        //    {
        //        tth = GetTradeSummaryHistory(settlementid, pdate);
        //    }
        //    return tth;
        //}

        ///// <summary>
        ///// 查询某天最大结算编号的成交汇总
        ///// </summary>
        ///// <param name="settlementid">结算编号</param>
        ///// <param name="pdate">日期</param>
        ///// <returns></returns>
        //private System.Collections.Generic.List<T_TradeDetail_Summary> GetTradeSummaryHistory(int settlementid, string pdate)
        //{
        //    System.Collections.Generic.List<T_TradeDetail_Summary> tth = new System.Collections.Generic.List<T_TradeDetail_Summary>();
        //    string sql = "select * from T_TradeDetail_Summary where SettlementId='" + settlementid + "' and tradingday='" + pdate + "'";
        //    OracleDataReader sdr = Common.ADO.Tools.OracleHelper.ExecuteReader(sql);
        //    while (sdr.Read())
        //    {
        //        T_TradeDetail_Summary s = new T_TradeDetail_Summary();
        //        s.AccountId = Convert.ToInt32(sdr["accountid"]);
        //        s.TradingDay = sdr["TradingDay"].ToString();
        //        s.Brokerid = Convert.ToString(sdr["Brokerid"]);
        //        s.CloseProfit = Convert.ToDouble(sdr["CloseProfit"]);
        //        s.CloseProfit2 = Convert.ToDouble(sdr["CloseProfit2"]);
        //        s.Commission = Convert.ToDouble(sdr["Commission"]);
        //        s.TradePrice = Convert.ToDouble(sdr["TradePrice"]);
        //        s.Direction = Convert.ToString(sdr["Direction"]);
        //        s.HedgeFlag = Convert.ToString(sdr["HedgeFlag"]);
        //        s.Id = Convert.ToInt32(sdr["Id"]);
        //        s.InstrumentId = Convert.ToString(sdr["InstrumentId"]);
        //        s.Investorid = Convert.ToString(sdr["Investorid"]);
        //        s.OffsetFlag = Convert.ToString(sdr["OffsetFlag"]);
        //        s.SettlementId = Convert.ToInt32(sdr["SettleMentId"]);
        //        s.TotalCost = Convert.ToDouble(sdr["TotalCost"]);
        //        s.Volume = Convert.ToInt32(sdr["Volume"]);
        //        tth.Add(s);
        //    }
        //    sdr.Close();
        //    return tth;
        //}

        ///// <summary>
        ///// 每天都需要执行的把Server中的数据导入到分析系统中的方法
        ///// </summary>
        ///// <param name="pdate">日期</param>
        //public void CopyServerTradeSummaryDataIntoBenefit(string pdate, DB.DBManager db)
        //{
        //    Data.ServerData.T_TradeDetail_Summary h = new Data.ServerData.T_TradeDetail_Summary();
        //    List<Data.ServerData.T_TradeDetail_Summary> tth = h.GetInfo(pdate);
        //    foreach (Data.ServerData.T_TradeDetail_Summary ha in tth)
        //    {
        //        db.TradeDetailSummary.Add(ha);
        //    }
        //    db.SaveChanges();
        //}


        ///// <summary>
        ///// 删除某日的所有持仓明细记录
        ///// </summary>
        ///// <param name="pdate"></param>
        //public void DeleteDayTradeSummaryFromBenefit(string pdate, DB.DBManager db)
        //{
        //    var historys = from t in db.TradeDetailHistory where t.TradingDay.Equals(pdate) select t;
        //    foreach (Data.ServerData.T_TradeDetail_History ha in historys)
        //    {
        //        db.TradeDetailHistory.Remove(ha);
        //    }
        //    db.SaveChanges();
        //}
    }
}